# index蓝图的视图
from flask import render_template, request, jsonify

from . import index_blu


@index_blu.route('/')
def index():
    return "hello,this is 首页!"


@index_blu.route('/menu')
def menu():
    data = {"code": 2000, "menu": {"\u8d44\u6e90\u7ba1\u7406": {"\u6d4b\u8bd5\u8bbe\u5907": "/resources/device",
                                                                "\u6392\u671f": "/resources/scheduling",
                                                                "\u5361\u8f66\u4e4b\u5bb6\u4e1a\u52a1\u4fe1\u606f\u8868": "/resources/project_information",
                                                                "TestCase": "/resources/testcase",
                                                                "\u8ba1\u5212\u4efb\u52a1": "/resources/add_task"},
                                   "\u8d28\u91cf\u7ba1\u7406": {
                                       "\u8d28\u91cf\u6570\u636e\u6807\u51c6": "/quality/quality",
                                       "bug\u7edf\u8ba1": "/quality/bug_statistics",
                                       "bug\u7387\u8ba1\u7b97": "/quality/bug_calculate",
                                       "bug\u7387\u7edf\u8ba1": "/quality/calculate",
                                       "\u9879\u76ee\u7edf\u8ba1\uff08\u5468\uff09": "/quality/procount"},
                                   "\u6d4b\u8bd5\u5de5\u5177": {"YApi": "/yapi",
                                                                "\u54cd\u5e94\u65f6\u95f4\u6d4b\u8bd5": "/time_test",
                                                                "Arachni": "/test_tools/arachni"},
                                   "\u63a5\u53e3\u76d1\u63a7": {"\u4efb\u52a1\u7ba1\u7406": "/monitor/task_list",
                                                                "\u76d1\u63a7\u7ed3\u679c": "/monitor/result"},
                                   "\u5b9e\u7528\u5de5\u5177": {"\u5468\u62a5\u5de5\u5177": "/weekly_index"},
                                   "\u6301\u7eed\u96c6\u6210": {"\u4efb\u52a1\u7ba1\u7406": "/ci/",
                                                                "\u81ea\u52a8\u5316\u62a5\u544a": "/ci/appreport"}}}
    return jsonify(data)


@index_blu.route('/user/jinyue', methods=['get'])
def jinyue():
    return jsonify({"code": 20000, "data": "沙子"})


@index_blu.route('/user/info', methods=['get'])
def info():
    return jsonify({"code": 20000, "data": {"roles": ["admin"], "introduction": "I am a super administrator",
                                            "avatar": "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
                                            "name": "Super Admin"}})


@index_blu.route('/testhtml', methods=['get'])
def testhtml():
    return render_template('pro.html')


#

@index_blu.route('/user/testpost', methods=['post'])
def testpost():
    if request.method == 'POST':
        try:
            req = str(request.get_data())
            # req += "返回个成功"
            # print(request.get_data())
            return jsonify({"code": 20000, "state": "1", "ms": str(req)})
        except Exception as e:
            ret = {"state": "0", "ms": str(e)}

    return jsonify(ret)

# @index_blu.route('/testpost', methods=['post'])
# def testpost1():
#     if request.method == 'POST':
#         try:
#             req=request.form.get("aaa")
#             # print(req)
#             # req = str(request.get_data())
#             req += "返回个成功"
#             # req = (type(req))
#             return jsonify(req)
#         except Exception as e:
#             ret = {"code" : 20000, "state": "0", "ms": str(e)}
#     else:
#         if defect == []:
#             ret = {"code" : 20000, "state": "1", "filename": filename, "defect": defect}
#         else:
#             ret = {"code" : 20000, "state": "2", "filename": filename, "defect": defect}
#     return jsonify(ret)

#
# @index_blu.route('/testpost', methods=['post'])
# def testpost():
#     if request.method == 'POST':
#         try:
#             req = str(request.get_data())
#             req += "返回个成功"
#             # req = (type(req))
#             return jsonify(req)
#         except Exception as e:
#             ret = {"state": "0", "ms": str(e)}
#     else:
#         if defect == []:
#             ret = {"state": "1", "filename": filename, "defect": defect}
#         else:
#             ret = {"state": "2", "filename": filename, "defect": defect}
#     return jsonify(ret)
